package cn.parllay.dingdangproject.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2016/7/9.
 */
// 保存
// 读取
public class SpUtils {//ctrl+g
    public static final String IS_LOGIN = "is_login";
    public static final String MOBILE = "mobile";
    public static final String USER_ID = "userId";
    public static final String STORE_ID = "storeId";
    public static final String STORE_NAME = "storeName";
    public static final String ROLE = "role";
    public static final String IS_NOTICE_ON = "is_notice_on";
    public static final String IS_RING_ON = "is_ring_on";
    public static final String IS_SHAKE_ON = "is_shake_on";
    public static final String RING_NAME = "ring_name";
    public static final String WXUID = "wxUid";
    public static final String TOKEN = "token";
    public static final String WXSID = "wxSid";
    public static final String DINGSTORE_NO = "dingstore_no";
    public static final String TOKEN_REFESH_TIME = "token_refesh_time";
    public static final String NICK_NAME = "employeeName";
    public static final String STORE_NO = "store_no";
    public static final String LOGIN_TIME = "login_time";
    public static final String COMPANYI_ID = "companyId";
    public static final String PASS_WORD = "password";
    public static final String STORE_LOGO = "store_logo";
    public static final String LINE_STATUS = "lineStatus";

    private static SpUtils instance = new SpUtils();
    private static SharedPreferences mSp = null;
    
    public static SpUtils getInstance(Context context){

        if(mSp == null) {
            mSp = context.getSharedPreferences("dingdang",Context.MODE_PRIVATE);
        }

        return instance;
    }

    // 保存
    public void save(String key, Object value){

        if(value instanceof String) {
            mSp.edit().putString(key, (String) value).commit();
        }else if(value instanceof Boolean) {
            mSp.edit().putBoolean(key, (Boolean) value).commit();
        }else if(value instanceof  Integer) {
            mSp.edit().putInt(key, (Integer) value).commit();
        }else if(value instanceof Long) {
            mSp.edit().putLong(key, (Long) value).commit();
        }
    }

    // 读取
    // 读取String类型数据
    public String getString(String key, String defValue){
        return mSp.getString(key, defValue);
    }

    // 读取boolean类型数据
    public boolean getBoolean(String key, boolean defValue){
        return mSp.getBoolean(key, defValue);
    }

    // 读取int类型数据
    public int getInt(String key, int defValue){
        return mSp.getInt(key, defValue);
    }

    // 读取long类型数据
    public long getLong(String key, long defValue){
        return mSp.getLong(key, defValue);
    }



}
